package com.gsit.expenditure.utils;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.TreeSet;

import org.apache.commons.beanutils.converters.NumberConverter;

import com.gsit.expenditure.client.domina.BillBean;
import com.gsit.expenditure.domain.Bill;
import com.gsit.expenditure.domain.Invoice;
import com.gsit.expenditure.domain.TravelBill;
import com.gsit.expenditure.report.domain.Client;

public class BilConverter {
	
	public static com.gsit.expenditure.report.domain.Bill converter(Bill bill){
		
		com.gsit.expenditure.report.domain.Bill mBill = new com.gsit.expenditure.report.domain.Bill();
		
		if(bill.getAmount() != null){
		BigDecimal amount = new BigDecimal(bill.getAmount());
		
		amount.setScale(2,RoundingMode.HALF_UP);
		mBill.setAmount(amount.doubleValue());
		mBill.setCreatedDate(bill.getCreatedDate());
		mBill.setReferenceNumber(bill.getReferenceNumber());
		if (bill instanceof TravelBill) {
			TravelBill travelBill=(TravelBill)bill;
			mBill.setParticulars(travelBill.getParticulars());
			mBill.setRate(travelBill.getRate());
			mBill.setDays(travelBill.getDays());
			mBill.setDistance(travelBill.getDistance());
			mBill.setCustomerName(travelBill.getCustomer().getFullName());
			mBill.setAddress1(travelBill.getCustomer().getAddress().getAddress1());
			mBill.setCity(travelBill.getCustomer().getAddress().getCity());
			mBill.setState(travelBill.getCustomer().getAddress().getState());
			//mBill.setVehicleNumber(bill.getVehicle().getVehicleNumber());
			
		}
	
		
		}
		return mBill;
	}
	
	
	public static Collection<com.gsit.expenditure.report.domain.Bill> converter(Collection <Bill> bills){
		Collection<com.gsit.expenditure.report.domain.Bill> mBills = new HashSet<com.gsit.expenditure.report.domain.Bill>();
	
		for (Bill bill : bills) {
			mBills.add(converter(bill));
		}
		return mBills;
	}
	
	
  public static Collection<com.gsit.expenditure.report.domain.Bill> converterBean(Collection <BillBean> billBeans){
		
		Collection<com.gsit.expenditure.report.domain.Bill> mBills = new HashSet<com.gsit.expenditure.report.domain.Bill>();
		int size = billBeans.size() ;
		
		if (size < 10) {
			int diff = 10 - size ;
			for(int index = 0 ;index <= diff ; index++)
			billBeans.add(new BillBean(new Bill()));
		}		
		for (BillBean billBean : billBeans) {
			mBills.add(converter(billBean.getBill()));
		}
		
		return mBills;
	
	}
}
	
	